package cn.ito.zjgsu.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.ito.zjgsu.constant.StatusCode;
import cn.ito.zjgsu.domain.PersonInfo;
import cn.ito.zjgsu.service.DepartmentPersonService;

@RestController
public class DepartmentPersonController {

	@Autowired
	DepartmentPersonService departmentPersonService;
	
	@RequestMapping(value="/staff/{departmentId}", method = RequestMethod.POST)
	public Map<String, Object> addStaff2Depart(@PathVariable int departmentId, @RequestBody int[] staffId) {
		for(int i : staffId) {
			departmentPersonService.addStaff(i, departmentId);
		}
		
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("STATUS", StatusCode.SUCCESS_STATUS);
		return result;
	}
	
	@RequestMapping(value="/staff/{departmentId}", method = RequestMethod.DELETE)
	public Map<String, Object> deleteStaffFromDepart(@PathVariable int departmentId, @PathVariable int staffId) {
		departmentPersonService.deleteStaff(staffId, departmentId);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("STATUS", StatusCode.SUCCESS_STATUS);
		return result;
	}
	
	@RequestMapping(value="/staff/staffs/{departmentId}", method = RequestMethod.GET)
	public Map<String, Object> findStaffByDepId(@PathVariable int departmentId) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<PersonInfo> persons = departmentPersonService.findStaff(departmentId);
		result.put("", persons);
		result.put("STATUS", StatusCode.SUCCESS_STATUS);
		return result;
	}
}
